<?php

namespace App\Http\Presenter;
use League\Fractal\TransformerAbstract;
use App\Http\Model\Activity;

use Prettus\Repository\Presenter\FractalPresenter;

class ActivityPresenter extends FractalPresenter {

    public function getTransformer()
    {
        return new class extends TransformerAbstract
        {
            public function transform(Activity $model)
            {
                $currentAt = time();
                $model->current_at = $currentAt;
                if ($currentAt < $model->start_at) {
                    $model->status = 1;
                } else if ($currentAt >= $model->start_at && $currentAt <= $model->end_at) {
                    $model->status = 2;
                } else {
                    $model->status = 3;
                }

//                $model->user_status = 1; // 未参与抢购
//                if ($model->log != null)
//                    $model->user_status = ($model->log->is_success == 1) ? 2 : 3; //2 参与抢购，成功 3参与抢购，未成功
//                unset($model->log);

                $model->is_shared = 0; // 未分享
                if ($model->share_log != null)
                    $model->is_shared = 1; // 已分享
                unset($model->share_log);

                return $model->toArray();
            }
        };
    }
}